package com.ellwood.IPGuard.common.core.exception;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;

/**
 * @ProjectName: IPGuard-boot
 * @PackageName: com.ellwood.IPGuard.common.core.exception
 * @ClassName: ServerException
 * @Description: // 自定义异常
 * @Author: Ellwood
 * @CreateDate: 2024/9/25 - 下午4:11
 * @Version: V1.0.0
 */
@Schema(description = "服务器异常")
@Data
@EqualsAndHashCode(callSuper = true)
public class ServerException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 1L;
        
        @Schema(description = "错误码")
    private int code;
        
        @Schema(description = "错误信息")
    private String msg;

    public ServerException(ErrorCode errorCode) {
        super(errorCode.getMsg());
        this.code=errorCode.getCode();
        this.msg=errorCode.getMsg();
    }

    public ServerException(String msg) {
        super(msg);
        this.code=ErrorCode.INTERNAL_SERVER_ERROR.getCode();
        this.msg=msg;
    }

    public ServerException(String message, Throwable cause) {
        super(message, cause);
        this.code = ErrorCode.INTERNAL_SERVER_ERROR.getCode();
        this.msg = msg;
    }

}
